<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input id="backTop" value="回到顶部" type="button"/>
<script>
    window.onload=function()
   {
       var oBackTop = document.getElementById('backTop');
       var timer=null;
       var bSys=true;
       window.onscroll=function()
       {
           if(!bSys){
               clearInterval(timer);
           }
           bSys=false;
       }
       oBackTop.onclick = function () {
        timer = setInterval(
            function () {
                var oScrollTop = document.documentElement.scrollTop || document.body.scrollTop;
                var oSpeed = Math.floor(-oScrollTop / 8);
                if (oScrollTop == 0) {
                    clearInterval(timer);
                }
                bSys=true;
                document.documentElement.scrollTop = oScrollTop + oSpeed;
            }, 30
        )
     }
   }
</script>
<style>
    body{
        min-height: 3000px;
    }
    #backTop{
        position: fixed;
        bottom: 30px;
        right: 30px;
    }
</style>
</body>
</html>
